//
//  LOLEquipViewController.m
//  LOLXXbox
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 Grasstrio. All rights reserved.
//

#import "LOLEquipViewController.h"
#import "LOLEquipCell.h"
#import <AFNetworking.h>
#import "LSZNetWorkTools.h"
#import "LOLEquipAAAModel.h"
#import "LOLEquipNextViewController.h"
@interface LOLEquipViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;

@end

@implementation LOLEquipViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"物品分类";
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatTableView];
    [self getData];
}

- (void)creatTableView{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[LOLEquipCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.tableView];
    self.dataSource = [NSMutableArray array];
    
}

- (void)getData{
    [LSZNetWorkTools getWithUrl:@"http://lolbox.duowan.com/phone/apiZBCategory.php" parameter:nil httpHeader:nil resposeType:ResponseTypeJSON success:^(id result) {
        NSArray *array = result;
        for (NSDictionary *dic in array) {
            LOLEquipAAAModel *model = [[LOLEquipAAAModel alloc] initWithDataSource:dic];
            [self.dataSource addObject:model];
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
        
    } fail:^(NSError *error) {
        
    }];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LOLEquipCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.equipModel = self.dataSource[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 64;
}
#pragma mark -- 点击跳转下一界面
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    LOLEquipNextViewController *nextVC = [[LOLEquipNextViewController alloc] init];
    LOLEquipAAAModel *model = self.dataSource[indexPath.row];
    nextVC.myTag = model.tag;
    nextVC.myText = model.text;
    [self.navigationController pushViewController:nextVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
